package com.集合.GradeSort;
//按总分从高到低进行排序-------比较器排序
import java.util.Comparator;
import java.util.TreeSet;
public class TreeSetDemo1 {
    public static void main(String[] args) {
        TreeSet<Student1> ts = new TreeSet<Student1>(new Comparator<Student1>(){
            public int compare(Student1 a, Student1 b){
                //按总分排序
                int sum1 = a.getChinese()+a.getMath();
                int sum2 = b.getChinese()+b.getMath();
                //
                int sum3 = sum1==sum2 ?a.getName().compareTo(b.getName()):sum1-sum2;
                return sum3;
            }
        });
        Student1 s1 = new Student1("zhangsan",80,96);
        Student1 s2 = new Student1("lishi",96,80);
        Student1 s3 = new Student1("jack",88,97);
        Student1 s4 = new Student1("tom",80,96);
        ts.add(s1);ts.add(s2);ts.add(s3);ts.add(s4);
        for(Student1 s:ts){
            System.out.println(s);
        }
    }
}
